<!DOCTYPE html >
<html>
<head>
    <title>Diamond GIA统一认证修改密码</title>
    <meta charset="UTF-8"/>
    <link rel="shortcut icon"  href="../static/images/title.png" th:href="@{images/title.png}">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="_csrf_parameter" th:content="${_csrf.parameterName}"
          th:if="${_csrf}" />
    <meta name="_csrf_header" th:content="${_csrf.headerName}"
          th:if="${_csrf}" />
    <meta name="_csrf" th:content="${_csrf.token}" th:if="${_csrf}" />
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<header>
    <div class="navbar navbar-dark box-shadow">
    </div>
</header>
<section class="text-center">
    <div class="container">
        <div class="row">
            <div class="navbar-header col-md-4 col-md-offset-4">

            </div>
        </div>
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h2 class="panel-title" href="/index">
                            <a href="/index" style="font-size: larger">Diamond GIA统一认证平台</a></h2>
                    </div>
                    <div class="panel-body">
                        <div name="form-signin">
                            <div class="form-group">
                                <input class="form-control" placeholder="用户名" name="id" id="id" type="text" th:value="${authentication.name}"/>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="原密码" name="password" id="password" type="password"
                                       value=""/>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="新密码" name="newPassword" id="newPassword" type="password"
                                       value=""/>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="确定新密码" name="rnewPassword" id="rnewPassword" type="password"
                                       value=""/>
                            </div>
                            <input class="btn btn-lg btn-success btn-block" type="submit" id="submit" value="确定修改"/>
                            <p id="errorInfo"></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<nav class="navbar navbar-default navbar-fixed-bottom">
    <div class="container">
        <div class="text-center">copyright 2021 hoioy.com 版权所有</div>
    </div>
</nav>
</body>
<script th:inline="javascript" type="text/javascript">
    /*<![CDATA[*/
    var token = $("meta[name='_csrf']").attr("content");
    var header = $("meta[name='_csrf_header']").attr("content");
    $(document).ajaxSend(function(e, xhr, options) {
        xhr.setRequestHeader(header, token);
    });

    $("#submit").click(changePass);
    function changePass() {
        var id = $('#id').val();
        var password = $('#password').val();
        var newPassword = $('#newPassword').val();
        var rnewPassword = $('#rnewPassword').val();

        if (newPassword != rnewPassword) {
            $("#errorInfo").text("两次输入密码不一致");
        } else {
            var url = "changePassword?id=" + id + "&password=" + password + "&newPassword=" + newPassword;
            $.post(url, {}, function (data) {
                if (data.code==200) {
                    window.location = "/index";
                } else{
                    $("#errorInfo").text(data.message);
                }
            });
        }
    }
    /*]]>*/
</script>
</html>